/**
 * Created by Administrator on 2017/4/16 0016.
 */
mvc.controller = {};

function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null)
        return unescape(r[2]);
    return null;
}

mvc.controller.getCategories = function () {

    var $data = '';
    mvc.model.getCategories($data, mvc.view.getCategories);
}
mvc.controller.getAbout = function () {

    var $data = '';
    mvc.model.getAbout($data,mvc.view.getAbout);
}
mvc.controller.getImage = function () {
    var $data;
        $data = 'categories_id=1';
    mvc.model.getImage($data,mvc.view.getImg);
}
mvc.controller.getImage01 = function (id) {
    var $data;
    $data = 'categories_id='+id;
    console.log($data);
    mvc.model.getImage($data,mvc.view.getImg);
}
mvc.controller.getArticleList = function () {

    var $data = 'page=1&article_categories=1';
    mvc.model.getArticleList($data,mvc.view.getArticleList);
}
mvc.controller.getArticleList01 = function (id) {

    var $data = 'page=&article_categories='+id;
    mvc.model.getArticleList($data,mvc.view.getArticleList);
}
mvc.controller.getArticleList02 = function (id,page) {

    var $data = 'page='+page+'&article_categories='+id;
    mvc.model.getArticleList($data,mvc.view.getArticleList);
}
mvc.controller.getAboutMe = function () {

    var $data = '';
    mvc.model.getAboutMe($data,mvc.view.getAboutMe);
}
mvc.controller.getArticle = function(){


    var article_id = getQueryString('article_id');
    var $data = 'article_id='+article_id;
    //console.log($data);
    mvc.model.getArticle($data,mvc.view.getArticle);
}
mvc.controller.login = function (name,pwd) {

    var $data ='admin_name='+name+'&admin_password='+pwd;
    mvc.model.login($data,mvc.view.login);
}
mvc.controller.getArticleList03 = function () {

    var $data = 'page=1&article_categories';
    mvc.model.getArticleList03($data,mvc.view.getArticleList03);
}
mvc.controller.getCategories01 = function () {

    var $data = '';
    mvc.model.getCategories($data, mvc.view.getCategories01);
}
mvc.controller.deleteCategories = function (id) {

    var admin_name = localStorage.getItem('admin_name');
    var token = localStorage.getItem('token')
    var $data = 'categories_id='+id+"&admin_name="+admin_name+"&admin_token="+token;
    mvc.model.deleteCategories($data, mvc.view.deleteCategories);
}
mvc.controller.addCategories = function (name,introduce) {

    var admin_name = localStorage.getItem('admin_name');
    var token = localStorage.getItem('token')
    var $data = 'categories_name='+name+"&categories_introduce="+introduce+"&admin_name="+admin_name+"&admin_token="+token;
    mvc.model.addCategories($data, mvc.view.addCategories);
}
mvc.controller.updateCategories = function (id,name,introduce) {

    var admin_name = localStorage.getItem('admin_name');
    var token = localStorage.getItem('token')
    var $data = 'categories_id='+id+'&categories_name='+name+"&categories_introduce="+introduce+"&admin_name="+admin_name+"&admin_token="+token;
    console.log($data);
    mvc.model.updateCategories($data, mvc.view.updateCategories);
}
mvc.controller.getCategoriesInfo = function () {
    var id = getQueryString('id');
    var admin_name = localStorage.getItem('admin_name');
    var token = localStorage.getItem('token')
    var $data = 'categories_id='+id+"&admin_name="+admin_name+"&admin_token="+token;
   // console.log($data);
    mvc.model.getCategoriesInfo($data, mvc.view.getCategoriesInfo);
}
mvc.controller.deleteArticle = function (id) {

    var admin_name = localStorage.getItem('admin_name');
    var token = localStorage.getItem('token')
    var $data = 'article_id='+id+"&admin_name="+admin_name+"&admin_token="+token;
    mvc.model.deleteArticle($data, mvc.view.deleteArticle);
}
mvc.controller.getArticleList04= function (page) {

    var $data = 'page='+page+'&article_categories=';
    mvc.model.getArticleList($data,mvc.view.getArticleList03);
}
mvc.controller.getArticleInfo = function () {

    var article_id = getQueryString('id');
    var $data = 'article_id='+article_id;
    mvc.model.getArticle($data,mvc.view.getArticle01);
}
mvc.controller.updateArticleInfo =function (article_id,article_title,article_categories,article_content,article_shortContent) {

    var admin_name = localStorage.getItem('admin_name');
    var token = localStorage.getItem('token')
    //var $data = 'article_id='+article_id+'&article_content='+article_content+'&article_categories='+article_categories+'&article_title='+article_title+'&admin_name='+admin_name+'&admin_token='+token;
    //console.log($data);
    var $data ={
        'article_id':article_id,
        'article_content':article_content,
        'article_categories':article_categories,
        'article_title':article_title,
        'admin_name':admin_name,
        'admin_token':token,
        'article_shortContent':article_shortContent
    }
    //console.log($data);
    mvc.model.updateArticleInfo($data,mvc.view.updateArticleInfo);
}
mvc.controller.addArticleInfo =function (article_title,article_categories,article_content,article_shortContent) {

    console.log(article_shortContent);
    var admin_name = localStorage.getItem('admin_name');
    var token = localStorage.getItem('token');
    var data = {
        'article_content' : article_content,
        'article_categories': article_categories,
        'article_title' : article_title,
        'admin_name' : admin_name,
        'admin_token' : token,
        'article_shortContent':article_shortContent,

    }
    mvc.model.addArticleInfo(data,mvc.view.addArticleInfo);
}
mvc.controller.getAbout01 = function () {

    var $data = '';
    mvc.model.getAbout01($data,mvc.view.getAbout01);
}
mvc.controller.updateAbout01 = function (about_text,about_shortContent) {

    var admin_name = localStorage.getItem('admin_name');
    var token = localStorage.getItem('token')
    //var $data = 'about_text='+about_text+'&admin_name='+admin_name+'&admin_token='+token;
    var $data ={
        'about_text':about_text,
        'about_shortContent':about_shortContent,
        'admin_name':admin_name,
        'admin_token':token,
    }
    mvc.model.updateAbout01($data,mvc.view.updateAbout01);
}
mvc.controller.sengRegisterEmail = function (email) {

    var $data = {
        'email':email,
    };
    mvc.model.sendRegisterEmail($data,mvc.view.sendRegisterEmail);
    
}
mvc.controller.register = function (email,verifyCode,nickName,password) {

    var $data = {
        'email':email,
        'verifyCode':verifyCode,
        'nickName':nickName,
        'password':password
    }

    mvc.model.register($data,mvc.view.register);
}
mvc.controller.userLogin = function (email,password) {

    var $data = {
        'email':email,
        'password':password
    }

    mvc.model.userLogin($data,mvc.view.userLogin);
}